#include					"Graphics.hh"

Graphics::Graphics()
	: _window(new sf::RenderWindow(sf::VideoMode(WIN_SIZE, WIN_SIZE), WIN_NAME)), _screenPos(0)
{
    _screens.push_back(new Menu(*_window));
    _screens.push_back(new Map(*_window));
}

Graphics::~Graphics()
{
}

void                        Graphics::run()
{
    while (_window->IsOpened())
    {
        eventManager();
        display();   
    }
}

void                        Graphics::eventManager()
{
    sf::Event               event;
    while (_window->GetEvent(event))
    {
        if (event.Type == sf::Event::Closed)
            _window->Close();
        else if ((event.Type == sf::Event::MouseButtonPressed))
            {
                if (_screens[_screenPos]->mouseButtonEvent(event.MouseButton) && !_screenPos)
                   _screens[++_screenPos]->initPlayers(_screens[0]->getGameType());
            }
        else if ((event.Type == sf::Event::MouseMoved) && _screenPos == 0)
            _screens[_screenPos]->mouseMoveEvent(event.MouseMove);
    }
}

void                        Graphics::display()
{
    _window->Clear();
    _screens[_screenPos]->draw();
    _window->Display();
}